<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="DataTables/datatables.min.css"/>
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>钱胆管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	基础信息管理
	<span class="c-gray en">&gt;</span>
	钱胆管理
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container" id="app">
	<div class="text-c">
		<form id="queryForm">
			<span class="select-box inline" v-if="isAdmin">
				<select class="select" id="companyid" name="comid" onchange="queryOffice(this.value)"></select>
			</span>
			<span class="select-box inline">
				<select class="select" id="officeid" name="officeId">
					<option value="">请选择票务室</option>
				</select>
			</span>
			<input type="text" name="id" id="id" placeholder="胆(C)/包(R)/大包(P)号" style="width:250px" class="input-text" v-model="msg">
			<button class="btn btn-success" type="button" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		</form>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a v-if="isAdmin" href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 删除</a>
			<a v-if="isAdmin" class="btn btn-primary radius" onclick="system_category_add('添加票胆','baseinfo-cashbox-add.html')" href="javascript:;"><i
				 class="Hui-iconfont">&#xe600;</i> 添加票胆</a>
			<a id="parentDom" class="btn btn-warning radius" href="javascript:;" onclick="cashbox_updateMoreById('批量需改','baseinfo-cashbox-update.html','','','500')"><i
				 class="Hui-iconfont">&#xe6df;</i> 批量修改</a><!--  onclick="cashbox_updateMoreById()" -->
			<button name="" id="excelId" class="btn btn-success" type="submit" onclick="excelAll();">导出Excel</button>
		</span>
	</div>
	<div class="mt-20">
		<table id="list" class="table table-border table-bordered table-hover table-bg table-sort">
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="DataTables/datatables.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/jquery.table2excel.js"></script>
<script type="text/javascript">
/*系统-车队-添加*/
function system_category_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*系统-车队-编辑*/
function system_category_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*系统-车队-删除*/
function system_category_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}

/*编辑*/
function cashbox_updateById(title, url, id, w, h) {
	layer_show(title, url + "?id=" + id, w, h);

}
/* 批量修改 */
function cashbox_updateMoreById(title, url, id, w, h) {
	var checkID = '';//定义一个空数组
	var members = $("input[name='ids']:checked");
	$(members).each(function(i){//把所有被选中的复选框的值存入数组
		checkID = checkID + $(this).val() + ',';
	});
	if (members.length > 0) {
		localStorage.setItem("cashboxAll", checkID);
		layer_show(title, url + "?id=all", w, h);
	} else {
		layer.open({
			title: '批量修改',
			content: '未选择任何修改项，请重新选择!'
		});
	}
}

/*系统-票胆-删除*/
function datadel() {
	var checkID = '';//定义一个空数组
	var members = $("input[name='ids']:checked");
	$(members).each(function(i){//把所有被选中的复选框的值存入数组
		checkID = checkID + $(this).val() + ',';
	});
	if (members.length == 0) {
		layer.open({
			title: '删除',
			content: '未选择任何删除项，请重新选择!'
		});
		return;
	} else {
		layer.confirm('确认要删除吗？', function(index) {
			if (checkID == "") {
				layer.open({
					content: "请选择要删除的胆/包",
					title: '删除胆/包',
					yes: function(index, layero) {
						layer.close(index); //如果设定了yes回调，需进行手工关闭
					}
				});
				return;
			}
			$.ajax({
				type: 'post',
				url: ipAddress + "base/cashbox/delCashboxsByIds",
				data: {
					"ids": checkID
				},
				cache: false,
				beforeSend: function(request) {
					request.setRequestHeader("Authorization", "Bearer " + getToken());
				},
				dataType: 'json',
				success: function(data) {
					//console.log(data.status)
					if (data.status) {
						layer.open({
							content: "删除成功！",
							title: '删除胆/包',
							yes: function(index, layero) {
								layer.close(index); //如果设定了yes回调，需进行手工关闭
								document.location.reload();
							}
						});
						//
					} else {
						alert("删除失败，请重新删除！")
					}
				},
				error: function() {
					//alert("请求失败");
				}
			});
		});
	}
}
</script>

<script type="text/javascript">
	var vm = new Vue({
		el : "#app",
		data : {
			msg : "",
			isAdmin : true
		},
		//在实例初始化之后，数据观测 (data observer) 和 event/watcher 事件配置之前被调用。
		beforeCreate:function(){
			console.log('beforeCreate');
		},
		/* 在实例创建完成后被立即调用。
		在这一步，实例已完成以下的配置：数据观测 (data observer)，属性和方法的运算，watch/event 事件回调。
		然而，挂载阶段还没开始，$el 属性目前不可见。 */
		created	:function(){
			console.log('created');
		},
		//在挂载开始之前被调用：相关的渲染函数首次被调用
		beforeMount : function(){
			console.log('beforeMount');
	
		},
		//el 被新创建的 vm.$el 替换, 挂在成功	
		mounted : function(){
			console.log('mounted');
		
		},
		//数据更新时调用
		beforeUpdate : function(){
			console.log('beforeUpdate');
				
		},
		//组件 DOM 已经更新, 组件更新完毕 
		updated : function(){
			console.log('updated');
				
		},
		methods: {
			query: function(){
				table.draw();
			}
		}
	});
	
	$(function(){
		$.ajax({
			url: ipAddress + 'base/company/getList',
			data: {
				order: "ordercode"
			},
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			method:'GET',
			success:function (data,status,request) {
				console.log(data);
				$("#companyid").append("<option value>请选择分公司</option>");
				for(var i = 0; i < data.length; i ++){
					$("#companyid").append("<option value='" + data[i].companyid + "'>" + data[i].companyname + "</option>");
				}
			},
			error:function (request, msg, obj) {
				var respTxtObj = JSON.parse(request.responseText);
				console.log(respTxtObj);
				console.log(respTxtObj.error);
				console.log(respTxtObj.error_description);
			}
		});
	});
	
	//查询票务室
	function queryOffice(companyid) {
		$.ajax({
			url: ipAddress + 'base/office/getList',
			data: {
				"company.companyid": companyid,
				order: "id"
			},
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			method:'GET',
			success:function (data,status,request) {
				console.log(data);
				$("#officeid").empty();
				$("#officeid").append("<option value>请选择票务室</option>");
				for(var i = 0; i < data.length; i ++){
					$("#officeid").append("<option value='" + data[i].id + "'>" + data[i].officename + "</option>");
				}
			},
			error:function (request, msg, obj) {
				var respTxtObj = JSON.parse(request.responseText);
				console.log(respTxtObj);
				console.log(respTxtObj.error);
				console.log(respTxtObj.error_description);
			}
		});
	}
	
	var table = $('#list').DataTable({
		language: {
			url: 'static/h-ui.admin/js/de_DE.txt'
		},
		//stateSave: true,
		"lengthMenu":[10, 50, 100],
		"pageLength": 100,
		searching: false,
		processing: true,
		serverSide: true,
		order: [[1, 'asc']],
		ajax: {
			 url: ipAddress + 'base/vcashbox/getTablePage',
			//url: 'http://localhost:8000/vehicle/getTablePage',
			type: 'GET',
			data: function ( data ) {
				var param = {};
				var userInfo = getUserInfo();
				var page = data.start == 0 ? 0 : data.start / data.length;
				var size = data.length;
				var order = data.columns[data.order[0].column].data + " " + data.order[0].dir;
				param.draw = data.draw;
				param.page = page;
				param.size = size;
				param.like = '%line.lineid%';
				param.order = order;
				var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
				formData.forEach(function (e) {
					if(e.value != ''){
						param[e.name] = e.value;
					}
				});
				if(hasRole('COMPANY')){
					vm.isAdmin = false;
					queryOffice(getUserInfo().company.companyid);
					param.comid = getUserInfo().company.companyid;
				}
				return param;
			}
		},
		columns: [
			{title: '<input type="checkbox" />',
				render: function(data, type, row, meta) {
					return "<input type='checkbox' name='ids' value='" + row.id +"'/>";
				}
			},
			{title: '分公司', name: 'companyName', data: 'companyName', defaultContent: '无'},
			{title: '票务室', name: 'officeName', data: 'officeName', defaultContent: '无'},
			{title: '大包/胆箱/款包号', name: 'id', data: 'id', defaultContent: '无'},
			{title: '类型', name: 'type', data: 'type', 
				render: function(data, type, row, meta) {
					return data == 'C' ? '钱胆' : data == 'R' ? '款包' : data == 'P' ? '大包' : '';
				}
			},
			{title: '状态', name: 'status', data: 'status', 
				render: function(data, type, row, meta) {
					return row.status == 1 ? '启用' : '停用';
				}
			},
			{title: '步骤', name: 'lockNo', data: 'lockNo', 
				render: function(data, type, row, meta) {
					if (data == 1) {
						return '<td>空胆(包)入柜</td>'
					} else if (data == 2) {
						return '<td>空胆领取</td>'
					} else if (data == 3) {
						return '<td>装胆运营</td>'
					} else if (data == 4) {
						return '<td>实胆卸车</td>'
					} else if (data == 5) {
						return '<td>实胆(包)入柜</td>'
					} else if (data == 6) {
						return '<td>实胆(包)运输</td>'
					} else if (data == 7) {
						return '<td>实胆(包)清点</td>'
					} else if (data == 8) {
						return '<td>空胆(包)运输</td>'
					} else {
						return ''
					}
				}
			},
			{title: '备注', name: 'summary', data: 'summary', defaultContent: '无'},
			{title: '操作', name: 'operation', 
				render: function(data, type, row, meta) {
					if (window.localStorage.getItem("user_name") == "admin") {
						if (row.status == 1) {
							return '<td><a style="text-decoration:none" onclick="stopUse(\'' + row.status + '\',\'' + row.id +
								'\');" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>&nbsp;&nbsp;<a style="text-decoration:none" href="javascript:;" onclick="cashbox_updateById(\'编辑\',\'baseinfo-cashbox-update.html\',\'' +
								row.id + '\',\'\',\'510\')" title="修改"><i class="Hui-iconfont">&#xe6df;</i></a></td>'
						} else {
							return '<td><a style="text-decoration:none" onclick="startUse(\'' + row.status + '\',\'' + row.id +
								'\');" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>&nbsp;&nbsp;<a style="text-decoration:none" href="javascript:;" onclick="cashbox_updateById(\'编辑\',\'baseinfo-cashbox-update.html\',\'' +
								row.id + '\',\'\',\'510\')" title="修改"><i class="Hui-iconfont">&#xe6df;</i></a></td>'
						}
					} else {
						return '';
					}
				}
			}
		],
		columnDefs: [
			{"orderable":false,"targets":[0,6]}
		]
	});
	
	
	function startUse(status, id) {
		//console.log("当前状态:" + status + ",id值：" + id)
		status = 0;
		layer.open({
			content: '是否启用',
			btn: ['启用', '取消'],
			yes: function(index, layero) {
				//按钮【按钮一】的回调
				$.ajax({
					type: 'POST',
					url: ipAddress + 'base/cashbox/updateOne',
					data: {
						status: status,
						id: id
					},
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					},
					dataType: 'json',
					async: false,
					success: function(data) {
						//window.location.reload(); //刷新当前页面
						query();
					},
					error: function(data) {
						//console.log(data.msg);
					}
				});
			}
		});
	}
	
	function excelAll(){
		$("#list").table2excel({
					exclude: ".noExl",
					name: "Excel Document Name",
					filename: "myFileName",
					exclude_img: true,
					exclude_links: true,
					exclude_inputs: true
				});
	}
	
	function stopUse(status, id) {
		layer.open({
			content: '是否停用？',
			btn: ['停用', '取消'],
			yes: function(index, layero) {
				//按钮【按钮一】的回调
				$.ajax({
					type: 'POST',
					url: ipAddress + 'base/cashbox/updateOne',
					data: {
						status: status,
						id: id
					},
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					},
					dataType: 'json',
					async: false,
					success: function(data) {
						window.location.reload() //刷新当前页面.
						
					},
					error: function(data) {
						//console.log(data.msg);
					}
				});
			}
		});
	}
</script>
</body>
</html>